<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="packagereportColumns"
      :dataSource="packagereportList"
      :customRow="handleRowClick"
    >
    </a-table>
    <j-vxe-table
      keep-source
      ref="detail"
      :columns="detailTable.columns"
      :dataSource="detailTable.dataSource"
      :maxHeight="300"
      :rowNumber="true"
      :rowSelection="false"
      :toolbar="false"
    />
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import { JVXETypes } from '@/components/jeecg/JVxeTable'

export default {
  name: 'packagereport',
  data() {
    return {
      description: '包装报工信息',
      packagereportList: [],
      packagereportColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '作业日报单号',
          align: 'center',
          dataIndex: 'code',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'workshopPlanCode',
        },
        // {
        //   title: '生产车间',
        //   dataIndex: 'planshopCode_dictText',
        //   align: 'center',
        // },
        {
          title: '包装车间',
          dataIndex: 'packshopCode_dictText',
          align: 'center',
        },
        {
          title: '包装班组',
          align: 'center',
          dataIndex: 'team',
        },
        // {
        //   title: '作业日期',
        //   align: 'center',
        //   dataIndex: 'workTime',
        //   customRender: function (text) {
        //     return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
        //   },
        // },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '制单日期',
          align: 'center',
          sorter: true,
          dataIndex: 'createTime',
        },
      ],
      detailTable: {
        dataSource: [],
        columns: [
          //   {
          //     title: '订单编号',
          //     dataIndex: 'orderCode',
          //     type: JVXETypes.normal,
          //     align: 'center',
          //     width: 150,
          //     defaultValue: '',
          //   },
          {
            title: '客户物料编码',
            key: 'customCode',
            type: JVXETypes.normal,
            align: 'center',
            width: '140px',
            defaultValue: '',
          },
          {
            title: '物料编码',
            align: 'center',
            dataIndex: 'productCode',
            key: 'productCode',
            width: '140px',
            type: JVXETypes.normal,
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'productBatchNo',
            key: 'productBatchNo',
            miniWdth: '140px',
            type: JVXETypes.normal,
          },
          {
            title: '规格型号',
            align: 'center',
            dataIndex: 'materialSpec',
            key: 'materialSpec',
            width: '140px',
            type: JVXETypes.normal,
          },
          {
            title: '配方号',
            key: 'formulaNumber',
            dataIndex: 'formulaNumber',
            align: 'center',
            width: 100,
            disabled: true,
          },
          {
            title: '主计量单位',
            align: 'center',
            dataIndex: 'meUnit_dictText',
            dictCode: 'ji_unit',
            key: 'meUnit_dictText',
            width: '100px',
            type: JVXETypes.normal,
          },
          {
            title: '计划数量',
            key: 'planQuantity',
            dataIndex: 'planQuantity',
            align: 'center',
            width: 120,
          },
          {
            title: '作业数量',
            key: 'workQuantity',
            align: 'center',
            width: '200px',
            defaultValue: '',
          },
        ],
      },
      url: {
        packagereportList: '/pro/tslProTeamworkReport/ByBatchNumber',
        detail: '/pro/tslProTeamworkReport/queryWorkshopById',
      },
    }
  },
  methods: {
    loadPackagereportData(batchNumber) {
      this.packagereportList = []
      if (batchNumber) {
        getAction(this.url.packagereportList, { batchNumber: batchNumber }).then((res) => {
          if (res.success) {
            this.packagereportList = res.result.records || res.result || []
          }
        })
      }
    },
    handleRowClick(record, index) {
      if (!record) return {}
      return {
        on: {
          click: (event) => {
            if (record.id) {
              this.loadDetail({ teamworkId: record.id })
            }
          },
        },
      }
    },
    loadDetail(params) {
      getAction(this.url.detail, params).then((res) => {
        if (res.success && res.result.length > 0) {
          this.detailTable.dataSource = res.result
        }
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
